package com.gxc;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

/**
 * @author 宫新程
 * @since 2018/12/15 10:48 AM
 */
public class Test_Ip {

  public static void main(String[] args) throws Exception {
    String ip = "60.209.105.178";
    // 请求的url
    URL url = new URL("http://ip.taobao.com/service/getIpInfo.php?ip=" + ip);
    URLConnection connection = url.openConnection();
    // 获取输入流,并获取数据
    InputStream inputStream = connection.getInputStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
    StringBuffer sb = new StringBuffer();
    String line;
    while ((line = reader.readLine()) != null) {
      sb.append(line);
    }
    // 关闭资源
    reader.close();
    inputStream.close();

    System.out.println(sb.toString());
  }
}
